<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{msg}}</h1>
        <button @click="update1">点击修改</button>
        <hr>
        <h1>{{json}}</h1>
        <button @click="update2">点击修改</button>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                msg:'监听数据变化',
                json:{
                    name:'刘为',
                    age:31,
                    sex:'男'
                }
            },
            methods: {
                update1(){
                    this.msg = '刘为是煞笔';
                },
                update2() {
                    this.json.name = '刘为是煞笔';
                }
            },
            watch:{
                msg(newVal,odlVal){
                    console.log('msg被修改')
                    console.log(newVal);
                    console.log(odlVal);
                },
                'json.name':(newVal,oldVal)=>{
                    console.log('json.name被修改');
                    console.log(newVal);
                    console.log(oldVal);
                }
            }
        })
    </script>
</body>
</html>